# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=scikit-learn
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.21.3
pkgrel=3
pkgdesc="A set of python modules for machine learning and data mining (mingw-w64)"
arch=('any')
url='http://scikit-learn.sourceforge.net/'
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python3"
         "${MINGW_PACKAGE_PREFIX}-python3-scipy"
         "${MINGW_PACKAGE_PREFIX}-python3-joblib")
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cython")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/scikit-learn/${_realname}/archive/${pkgver}.tar.gz"
        001-mingw-python-openmp-flag.patch
        002-openmp-cleanup-wait.patch)
sha256sums=('260f66e9c643207fe8cfe0995242060fdb14137b5e69a8dd273ac463b7e9426b'
            '11c9fedec28d882c25c90087ec3ef09f022dfd83c308574d023c89d19b5520f0'
            '33e868844768a8e3afe93056d3cb54e0e9e4fd491a1df2b29d9d925ac5b3cf93')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw-python-openmp-flag.patch
  patch -p1 -i ${srcdir}/002-openmp-cleanup-wait.patch

  cd ${srcdir}
  rm -rf python3-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python3-build-${CARCH}"
}

build() {
  msg "Python 3 build for ${CARCH}"
  cd "${srcdir}/python3-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package() {
  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/python3-${_realname}/COPYING

  install -d ${pkgdir}${MINGW_PREFIX}/share/doc/python3-${_realname}
  cp -r doc/tutorial ${pkgdir}${MINGW_PREFIX}/share/doc/python3-${_realname}/tutorial
}
